package edu.umassd.raddacl.dataset;

import edu.umassd.raddacl.Cluster;
import edu.umassd.raddacl.DataSet;

/**
 * Internal class used for creating objects.
 * 
 * @author Dan Avila
 * 
 */
public abstract class DefaultFactory
{
	/**
	 * Lookup method override.
	 * 
	 * @return
	 */
	protected abstract DefaultCluster createCluster();

	/**
	 * Lookup method override.
	 * 
	 * @return
	 */
	protected abstract Split createSplit();

	/**
	 * Wraps the incoming data set as a cluster.
	 * 
	 * @param dataSet
	 *            - the incoming data set.
	 * @return the dataset as a cluster.
	 */
	Cluster createCluster(DataSet dataSet)
	{
		DefaultCluster c = createCluster();

		c.populate(dataSet);

		return c;
	}

	/**
	 * Creates a new cluster from a parent cluster that contains only the points
	 * specified in the area with the provided split.
	 * 
	 * @param parent
	 *            - the parent cluster.
	 * @param split
	 *            - the sub area of the parent cluster where points for this
	 *            cluster lie.
	 * @return a newly created sub-cluster.
	 */
	Cluster createCluster(DefaultCluster parent, Split split)
	{
		DefaultCluster c = createCluster();

		try
		{
			c.populate(parent, split);

			return c;
		}
		catch (IllegalArgumentException e)
		{
			return null;
		}
	}
}
